import React from 'react';
import { Checkbox, message } from 'antd';
export default (props) => {
  const { type, title, datas, fieldNames, currentValue, clickConfirm } = props;
  return (
    <div className="offwards">
      <div className="restrict">{title}：</div>
      <div className="reduceWeight">
        {datas.map((item, index) => (
          <div
            key={item[fieldNames.value]}
            // className={`comfort ${item.checked && 'comfortBlue'}`}
            className={`comfort ${
              ((!currentValue && index === 0) ||
                (currentValue?.includes(`${item.value},`) && index !== 0)) &&
              'comfortBlue'
            }`}
            onClick={() => {
              let neaten = '';
              if(item.value){
                if (currentValue?.includes(`${item.value},`)) {
                  neaten = currentValue.replace(`${item.value},`, '');
                } else {
                  neaten = currentValue + `${item.value},`;
                }
              }
              clickConfirm(neaten || '');
              // let collectList = [];
              // datas[index].checked = !datas[index].checked;
              // datas.map((item) => {
              //     if (item.checked) {
              //         collectList.push(item.value);
              //     }
              // });
              // if (collectList.length) {
              //     clickConfirm(collectList.join(','));
              // } else {
              //     clickConfirm('');
              // }
            }}
          >
            {item[fieldNames.label]}
          </div>
        ))}
      </div>
    </div>
  );
};
